@extends('admin.main')
@section('content')
    <div class="daohang">
        <ul>
            <li>
                <button type="button" class="am-btn am-btn-default am-radius am-btn-xs"> 自定义菜单</button>
            </li>
        </ul>
    </div>
    <div class="admin-biaogelist">
        <div class="listbiaoti am-cf">
            <ul class="am-icon-flag on">
                菜单列表
            </ul>
            <dl>
                <button type="button" class="am-btn am-btn-danger am-round am-btn-xs am-icon-plus" onclick="window.location.href='{{urlAdmin('wechatMenus','getCreate')}}'">添加菜单</button>
            </dl>

        </div>
        <form class="am-form am-g">
            <table width="100%" class="am-table am-table-bordered am-table-radius am-table-striped am-table-hover">
                <thead>
                <tr class="am-success">
                    <th class="table-id">排序</th>
                    <th class="table-title">菜单名称</th>
                    <th class="table-type">菜单类型</th>
                    <th class="table-type">菜单Key</th>
                    <th class="table-type">菜单Url</th>
                    <th class="table-type">状态</th>
                    <th width="163px" class="table-set">操作</th>
                </tr>
                </thead>
                <tbody>
                @foreach($data as $v)
                    {{--<tr id="tr_{{$v->id}}">--}}
                        {{--<td> {{$v->name}}</td>--}}
                        {{--<td> {{$v->type == 'view' ? '链接' : '事件'}}</td>--}}
                        {{--<td> {{$v->key}}</td>--}}
                        {{--<td> {{$v->url}}</td>--}}
                        {{--<td> @if($v->status ==1 )<span class="btn btn-blue btn-xs">开启 </span> @else <span class="btn btn-danger btn-xs">未开启</span> @endif</td>--}}
                        {{--<td>{{$v->sort}}</td>--}}
                        {{--<td>--}}
                            {{--<a href="javascript:;" class="btn btn-info btn-xs edit"--}}
                               {{--onclick="loadHtml('{{urlAdmin('wechatMenus','getEdit',['id'=>$v['id']])}}','编辑')">--}}
                                {{--<i class="fa fa-edit"></i> 编辑</a>--}}
                            {{--<a href="javascript:;" onclick='deleteMenu("{{urlAdmin('wechatMenus','getDestroy',['id'=>$v['id']])}}","{{$v['id']}}")' class="btn btn-default btn-xs black"><i class="fa fa-trash-o"></i> 删除</a>--}}
                        {{--</td>--}}
                    {{--</tr>--}}
                <tr id="tr_{{$v->id}}">
                    <td><input type="text" class="am-form-field am-radius am-input-sm" value="{{$v->sort}}"/></td>
                    <td> {{$v->name}}</td>
                    <td> {{$v->type == 'view' ? '链接' : '事件'}}</td>
                    <td> {{$v->key}}</td>
                    <td> {{$v->url}}</td>
                    <td> @if($v->status ==1 )<span class="btn btn-blue btn-xs">开启 </span> @else <span class="btn btn-danger btn-xs">未开启</span> @endif</td>
                    <td><div class="am-btn-toolbar">
                            <div class="am-btn-group am-btn-group-xs">
                                <a href="{{urlAdmin('wechatMenus','getEdit',['id'=>$v['id']])}}" class="am-btn am-btn-default am-btn-xs am-text-secondary am-round">
                                    <span class="am-icon-pencil-square-o"></span>
                                </a>
                                <a href="javascript:;" onclick='deleteMenu("{{urlAdmin('wechatMenus','getDestroy',['id'=>$v['id']])}}","{{$v['id']}}")' class="am-btn am-btn-default am-btn-xs am-text-danger am-round">
                                    <span class="am-icon-trash-o"></span>
                                </a>
                            </div>
                        </div></td>
                </tr>
                    @if(isset($v->sub) && count($v->sub) > 0)
                        @foreach($v->sub as $s)
                            <tr  id="tr_{{$s->id}}">
                            <td><input type="text" class="am-form-field am-radius am-input-sm" value="{{$s->sort}}"/></td>
                            <td> <i style="margin-left:30px">├─  </i>{{$s->name}}</td>
                            <td> {{$s->type == 'view' ? '链接' : '事件'}}</td>
                            <td> {{$s->key}}</td>
                            <td> {{$s->url}}</td>
                            <td> @if($s->status ==1 )<span class="btn btn-blue btn-xs">开启 </span> @else <span class="btn btn-danger btn-xs">未开启</span> @endif</td>
                            <td><div class="am-btn-toolbar">
                                    <div class="am-btn-group am-btn-group-xs">
                                        <a href="{{urlAdmin('wechatMenus','getEdit',['id'=>$s['id']])}}" class="am-btn am-btn-default am-btn-xs am-text-secondary am-round">
                                            <span class="am-icon-pencil-square-o"></span>
                                        </a>
                                        <a href="javascript:;" onclick='deleteMenu("{{urlAdmin('wechatMenus','getDestroy',['id'=>$s['id']])}}","{{$s['id']}}")' class="am-btn am-btn-default am-btn-xs am-text-danger am-round">
                                            <span class="am-icon-trash-o"></span>
                                        </a>
                                    </div>
                                </div></td>
                            </tr>
                        @endforeach
                    @endif
                @endforeach
                </tbody>
            </table>
            <div class="am-btn-group am-btn-group-xs">
                <button type="button" class="am-btn am-btn-default am-text-success" onclick="makeMenu()"> 生成菜单</button>
                <span class="am-text-danger">&nbsp;注意：顶级菜单最多3个，子菜单最多5个</span>
            </div>
            <hr />
        </form>

       @include('admin.footer')
    </div>
@section('script')
<script>
    $(window).ready(function(){
        var res = "{{Session::get('res')}}";
        var message = "{{Session::get('message')}}";
        if (res) {
            layer.msg(message);
        }
    });

    function deleteMenu(url,id) {
        layer.confirm('您确定要删除吗？', {
            btn: ['确定', '取消'] //按钮
        }, function () {
            $.get(url, function (res) {
                var icon = 5;
                if (res.status) {
                    $("#tr_"+id).hide();
                    icon = 6;
                }
                layer.msg(res.msg,{icon:icon});
            });
        });
    }

    function makeMenu() {
        var url = '{{urlAdmin('wechatMenus','getMakeMenu')}}';
        $.get(url, function (res) {
            var icon = 6;
            if (res.status == 0) {
                icon = 5;
            }
            layer.msg(res.msg,{icon:icon});
        });
    }
</script>
@endsection
@endsection